#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QFile>
#include <QFileDialog>
#include <QDebug>
#include <QDateTime>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    connect(ui->pushButton, &QPushButton::clicked, [=](){
        QString path = QFileDialog::getOpenFileName(this, "打开文件");

        ui->lineEdit->setText(path);

        QFile file(path);
        file.open(QIODevice::ReadWrite);

        //file.write("【这是示例】");

        QString str = file.readAll();
        ui->textEdit->setText(str);

        file.close();

        QFileInfo fileinfo(path);
        qDebug() << "文件名为: " << fileinfo.fileName().toUtf8().data();
        qDebug() << "后缀名为: " << fileinfo.suffix().toUtf8().data();
        qDebug() << "文件大小为: " << fileinfo.size();
        qDebug() << "文件路径为: " << fileinfo.path().toUtf8().data();
        qDebug() << "是否为文件: " << fileinfo.isFile();

        QDateTime time1 = fileinfo.fileTime(QFileDevice::FileBirthTime);
        qDebug() << "创建时间为: " << time1.toString("yyyy-MM-dd hh::mm::ss");

        QDateTime time2 = fileinfo.lastModified();
        qDebug() << "创建时间为: " << time2.toString("yyyy-MM-dd hh::mm::ss");
    });



}

MainWindow::~MainWindow()
{
    delete ui;
}

